/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import entity.Customer;

/**
 *
 * @author cyhiew
 */
public class CustomerValidator implements Validator {

    @Override
    public boolean supports(Class<?> clazz) {
        return Customer.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {


        ValidationUtils.rejectIfEmpty(errors, "customerId", "gender.required");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "customerId", "gender.required");
        Customer user = (Customer) target;
        System.out.println("qwe" + user.getCustomerId());
        
        if (user.getCustomerId()==2) {
            errors.rejectValue("customerId", "gender.required");
        }

    }
}
